;(function()
	{
		var angularApp=angular.module("myApp",[]);
 	   	angularApp.controller('promotion',function($scope,$http)
 	   		{
/* 	   			$http({  
					   method:'post',  
					   url:'post.php',  
					   data:{name:"aaa",id:1,age:20},  
					   headers:{'Content-Type': 'application/x-www-form-urlencoded'},  
					   transformRequest: function(obj) {  
					     var str = [];  
					     for(var p in obj){  
					       str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));  
					     }  
					     return str.join("&");  
					   }  
					}).success(function(req){  
					       console.log(req);  
					}) */ 
 	   			$scope.promotions=[
 	   			{img:'source/temp/33.png',name:'56°泸州老窖，湿哒哒气温气温为',nowPrice:"109.00",oriPrice:"50.00"},
 	   			{img:'source/temp/33.png',name:'56°泸州',nowPrice:"109.00",oriPrice:"50.00"},
 	   			{img:'source/temp/33.png',name:'56°泸州老窖，湿哒哒气温气温为',nowPrice:"109.00",oriPrice:"50.00"},
 	   			{img:'source/temp/33.png',name:'56°泸州老窖，湿哒哒气温气温为',nowPrice:"109.00",oriPrice:"50.00"}];
 	   			$scope.recos=[
 	   			{img:'source/temp/33.png',name:'真実（しんじつ）は いつも ひとつ！ ',nowPrice:"109.00",oriPrice:"50.00"},
 	   			{img:'source/temp/33.png',name:'真実（しんじつ）は いつも ひとつ！ ',nowPrice:"109.00",oriPrice:"50.00"},
 	   			{img:'source/temp/33.png',name:'真実（しんじつ）は いつも ひとつ！ ',nowPrice:"109.00",oriPrice:"50.00"},
 	   			{img:'source/temp/33.png',name:'真実（しんじつ）は いつも ひとつ！ ',nowPrice:"109.00",oriPrice:"50.00"},
 	   			{img:'source/temp/33.png',name:'真実（しんじつ）は いつも ひとつ！ ',nowPrice:"109.00",oriPrice:"50.00"},
 	   			{img:'source/temp/33.png',name:'真実（しんじつ）は いつも ひとつ！ ',nowPrice:"109.00",oriPrice:"50.00"}];
 	   			$scope.swipers=[
		 	   	{img:"source/temp/2.jpg",href:"http://www.baidu.com"},
		 	   	{img:"source/temp/3.jpg",href:"http://www.baidu.com"},
		 	   	{img:"source/temp/4.jpg",href:"http://www.baidu.com"}];
		 	   	$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
						var swiper = new Swiper('.swiper-container', {
				        pagination: '.swiper-pagination',
				        paginationClickable: true,
				        spaceBetween: 30,
				        autoplay: 2500,
				        autoplayDisableOnInteraction:false,
				        loop:true
			    	});

				});
 	   		});
 	   	angularApp.directive('onFinishRender',function($timeout)
 	   	{
 	   		return {
	        restrict: 'A',
	        link: function (scope, element, attr) {
		            if (scope.$last === true) {
			                $timeout(function () {
			                    scope.$emit('ngRepeatFinished');
			                });
		            	}
		        	}
			    }
 	   	});
 	   	/*登陆方法*/
 	   	angularApp.controller("login",function($scope,$http,$timeout)
 	   	{
 	   	    $scope.show=false;
 	   		$scope.loginAction=function()
 	   		{
				$scope.userInfo={
					phone:$scope.u_phone,
					password:$scope.u_password
				};
 	   			$http({
					   method:'post',  
					   url:'post.php',  
					   data:$scope.userInfo,
					   headers:{'Content-Type': 'application/x-www-form-urlencoded'}
					}).success(function(req){
					    if(req)
                        {

                        }
                        else
                        {
                            $scope.info=req;
                            $scope.show=true;
                            $timeout(function(){
                                $scope.show=false;
                            },2000);
                        }
					})
 	   		};
 	   	});
 	   	var timer;
 	   	/*注册方法*/
 	   	angularApp.controller('register',function($scope,$http,$interval,$timeout)
 	   	{
			$scope.register={
				info:"",
				show:false
			};
 	   		$scope.argee=false;
 	   		$scope.getVercodeOk=false;
 	   		$scope.verDown="获取验证码";
/* 	   		var phoneReg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
 	   		$scope.$watch('u_phone',function(v)
 	   		{
 	   			if(phoneReg.test(v))
 	   			{
 	   				$scope.getVercodeOk=false;
 	   			}
 	   			else
 	   			{
 	   				$scope.getVercodeOk=true;
 	   			}
 	   		});*/
 	   		/*提交注册表单*/
 	   		$scope.registerAction=function()
 	   		{
 	   			 	$http({  
					   method:'post',  
					   url:'post.php',  
					   data:$(".login-in").serialize(),  
					   headers:{'Content-Type': 'application/x-www-form-urlencoded'}
					}).success(function(req){  
					       console.log(req);  
					});
 	   		};
 	   		/*获取验证码*/
 	   		$scope.get_vercode=function()
 	   		{
				$scope.getVercodeOk=true;
                $http({
                    method:'post',
                    url:'post.php',
                    data:$(".login-in").serialize(),
                    headers:{'Content-Type': 'application/x-www-form-urlencoded'}
                }).success(function(req){
                    if(req)
                    {
                        $scope.verDown=60;
                        timer=$interval(function()
                        {
                            $scope.verDown--;
                            if($scope.verDown<=0)
                            {
                                $scope.getVercodeOk=false;
                                $interval.cancel(timer);
                                $scope.verDown="获取验证码";
                            }
                        },1000);
                    }
                    else
                    {
                        $scope.register.info="手机号码错误";
                        $scope.register.show=true;
                        $timeout(function(){
                            $scope.register.show=false;
                        },2000);
                        $scope.getVercodeOk=false;

                    }
                });
 	   		}
 	   	});
        //分类控制
        angularApp.controller("classify",['$scope',function(scope)
        {
            scope.class=0;
            scope.classify_list=[
                {name:"葡萄酒",value:"1"},
                {name:"啤酒",value:"2"},
                {name:"红酒",value:"3"},
                {name:"白酒",value:"4"}
            ];
            scope.classify={
                brand:[{name:'拉菲',value:1},{name:'禅城',value:2},{name:'村正',value:3},{name:'妖刀',value:4},{name:'太刀',value:5}],
                type:[{name:'红葡萄酒',value:1},{name:'白葡萄酒',value:2},{name:'起泡酒',value:3}],
                price:[{name:'1-100',value:1},{name:'101-200',value:2},{name:'201-300',value:1}]
            }
        }]);
        var firstElem=0,classify_list=[];
        angularApp.directive('classifylist',function()
        {
            return {
                restrict:"A",
                link:function(scope,elem)
                {
                    classify_list.push(elem);
                    if(firstElem==0)
                    {
                        elem.addClass("left-selected");
                        firstElem++;
                    }
                    elem.bind('click',function()
                    {
                        for(var i=0;i<classify_list.length;i++)
                        {
                            if(classify_list[i].hasClass("left-selected"))
                            {
                                classify_list[i].removeClass("left-selected");
                                break;
                            }
                        }
                        this.className="left-selected";
                    })
                }
            }
        });
        angularApp.directive('brandlist',function()
        {
            return {
                restrict:'A',
                template:'<dd ng-repeat="i in classify.brand"><a href="#?value={{i.value}}" ng-bind="i.name"></a></dd>',
                replace:true
            }
        });
        angularApp.directive('typelist',function()
        {
            return {
                restrict:'A',
                template:'<dd ng-repeat="i in classify.type"><a href="#?value={{i.value}}">{{i.name}}</a></dd>',
                replace:true
            }
        });
        angularApp.directive('pricelist',function()
        {
            return {
                restrict:'A',
                template:'<dd ng-repeat="i in classify.price"><a href="#?value={{i.value}}">{{i.name}}</a></dd>',
                replace:true
            }
        });
	})();
